package admincow.servlet.regevabe;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admincow.dao.RegevabeDAO;
import admincow.vo.RegevabeVO;

/**
 * Servlet implementation class for Servlet: RegevabeNuevoServlet
 *
 */
 public class RegevabeNuevoServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public RegevabeNuevoServlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String a = request.getParameter("animal");
		int b = Integer.parseInt(request.getParameter("idevento"));
		String c = request.getParameter("RPbecerro");
		String d = request.getParameter("RPvaca");
		String e = request.getParameter("idusuario");
		String f = request.getParameter("fecha");
		String g = request.getParameter("descripcion");

		if (a.equals("B")){
			RegevabeVO vo = new RegevabeVO();
			vo.setIdevento(b);
			vo.setRPbecerro(c);
			vo.setIdusuario(e);
			vo.setFecha(f);
			vo.setDescripcion(g);
			
			RegevabeDAO dao = new RegevabeDAO();
			dao.insertarb(vo);
			
		}else{
			RegevabeVO vo = new RegevabeVO();
			vo.setIdevento(b);
			vo.setRPvaca(d);
			vo.setIdusuario(e);
			vo.setFecha(f);
			vo.setDescripcion(g);
			
			RegevabeDAO dao = new RegevabeDAO();
			dao.insertarv(vo);
		}


		RequestDispatcher rd = request
				.getRequestDispatcher("/regevabeBuscar.jsp");
		rd.forward(request, response);
	}   	  	    
}